package magic.doclet.html.blocks;

import magic.html.HTML.classes;
import magic.html.tag.block.Div;
import magic.html.tag.block.H2;
import magic.html.tag.inline.Img;

@classes("scene")
public class SceneDiv extends Div {

    @classes("title")
    public H2 title;

    @classes("screenshot")
    public Img screenshot;

    @classes("changes")
    public Changes changes;

    @classes("actions")
    public Actions actions;

    @classes("clear")
    public Div clear;

    public static class Actions extends Div {
	@classes("title")
	public H2 title;

	public ActionSetDiv scene;

	public ActionSetDiv drag;

	public Actions() {
	    super();
	    title.addText("Actions");
	    scene.title.setText("Set Scene");
	    drag.title.setText("Drag");
	}

	public String toHTML() {
	    if (scene.table.rows.size() == 0 && drag.table.rows.size() == 0)
		return "";
	    tagLine(title);
	    tagLine(scene);
	    tagLine(drag);
	    return super.toHTML();
	}

	public void setId(String id) {
	    this.id.set(id + "_actions");
	    scene.setId(id + "_actions_scene");
	    scene.setId(id + "_actions_drag");
	}

    }

    public static class Changes extends Div {

	@classes("title")
	public H2 title;

	public ChangeSetDiv added;

	public ChangeSetDiv removed;

	public Changes() {
	    super();
	    title.setText("Changes");
	    added.title.setText("Added");
	    removed.title.setText("Removed");
	}

	public String toHTML() {
	    if (added.table.rows.size() == 0 && removed.table.rows.size() == 0)
		return "";
	    tagLine(title);
	    tagLine(added);
	    tagLine(removed);
	    return super.toHTML();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see magic.html.HTML#setId(java.lang.String)
	 */
	@Override
	public void setId(String id) {
	    super.setId(id + "_changes");
	    added.setId(id + "_added");
	    removed.setId(id + "_removed");
	}

    }

    /**
     * @param index
     *            the scene index
     * @return true if the scene index is the same as that which would be
     *         generated by {@link #setId(int)}
     */
    public boolean isScene(int index) {
	return id.get().equals(generateId(index));
    }

    /**
     * generates the div id from the scene index @see {@link #generateId(int)}
     * 
     * @param i
     */
    public void setId(int i) {
	setId(generateId(i));
    }

    public void setId(String id) {
	super.setId(id);
	changes.setId(id);
	actions.setId(id);
    }

    public static String generateId(int sceneNumber) {
	return "scene" + sceneNumber;
    }

    public String toHTML() {
	tagLine(title);
	tagLine(screenshot);
	tagLine(changes);
	tagLine(actions);
	tagLine(clear);
	return super.toHTML();
    }

}
